def singleton(cls, *args, **kw):
    instance = {}
    def _singleton():
        if cls not in instance:
            instance[cls]=cls(*args, **kw)
        return instance[cls]
    return _singleton
@singleton
class Test():
    pass
if __name__ == '__main__':

    test1 = Test()
    test2 = Test()
    print(test1)
    print(test2)
    assert test1 is test2, "不是单例"